package com.example.mybatisplus.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.Entity.UserEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper //使用@Mapper注解要定义成一个接口interface,它将接口交给Spring进行管理，用于标识接口方法与数据库表之间的映射关系
public interface UserMapper extends BaseMapper<UserEntity> {
    @Select("SELECT * FROM user WHERE id = #{id}")
    UserEntity findById(@Param("id") Long id);  //方法参数有多个的时候，需要使用@Param，单参数方法可以不需要

    @Select("SELECT * FROM user WHERE name = #{name}")
    UserEntity findByName(@Param("name") String name);

    @Select("SELECT * FROM user WHERE email = #{email}")
    UserEntity findByEmail(@Param("email") String name);

    @Select("SELECT * FROM user ")//非分页查询，直接获取所有的用户信息
    List<UserEntity> findAll();

    @Select("select * from  user where age = #{age}") // 通过年龄分页查询
    IPage<UserEntity> selectUserByAge(Page<UserEntity> page, @Param("age") Integer age);
}
